#pragma execution_character_set("utf-8")
//https://blog.csdn.net/maoliran/article/details/51536593
#include <iostream>
#include "testCopy.h"
using namespace std;
/*
class A {
public:
    A() {
        cout << this << "--this is a constructor" << endl;
    }
    ~A() {
        cout << this << "--this is a destructor" << endl;
    }
    A(const A & another) {
        cout << this << "--copy cnnstructor from--" << & another << endl;
    }
    A & operator=(const A & other) {
        cout << this << "--assignment operator overloading from--" << &other << endl;
        return *this;//Compiler recommended
    }
};

//A func(A a) {
A func(A& a) {
    return a;
}

int main() {
    A x;
    A t;
    t = func(x);

    return 0;
}*/

class Person {
public:
    //无参（默认）构造函数
    Person() {
        cout << "无参构造函数!" << endl;
    }
    //有参构造函数
    Person(int a) {
        age = a;
        cout << "有参构造函数!" << endl;
    }
    //拷贝构造函数
    Person(const Person& p) {
        age = p.age;
        cout << "拷贝构造函数!" << endl;
    }
    //析构函数
    ~Person() {
        cout << "析构函数!" << endl;
    }
public:
    int age;
};

void test01()
{
    Person p1(18);
    //如果不写拷贝构造，编译器会自动添加拷贝构造，并且做浅拷贝操作
    Person p2(p1);

    cout << "p2的年龄为： " << p2.age << endl;
}

void test02()
{
    //如果用户提供有参构造，编译器不会提供默认构造，会提供拷贝构造
    Person p1; //此时如果用户自己没有提供默认构造，会出错
    Person p2(10); //用户提供的有参
    Person p3(p2); //此时如果用户没有提供拷贝构造，编译器会提供

    //如果用户提供拷贝构造，编译器不会提供其他构造函数
    Person p4; //此时如果用户自己没有提供默认构造，会出错
    Person p5(10); //此时如果用户自己没有提供有参，会出错
    Person p6(p5); //用户自己提供拷贝构造
}

//void PrintString(String string)
void PrintString(const String& string) //定义成引用，不会调用copy constructor
{
    //string[3]='j';

   // String copy = string;
    cout << string <<endl;
}


int main() {

  //  test01();

    /*
    Vector tttt;
    tttt.x=1.11111111111;
    tttt.y=1.11111111111;
    cout <<  tttt.x <<endl;

    Vector tttt2{2.22222222,2.22222222};
    tttt = tttt2;//test stuct copy
    cout <<  tttt.x <<endl;*/

    /*
    Vector*  tttt = new Vector();
    Vector*  tttt2 = tttt;
    tttt2->x=2;
    cout <<  tttt->x <<endl;//affect both tttt and tttt2
    cout <<  tttt2->x <<endl;*/

    String string = "tttt";
    String second = string; //one copy happen here

    second[2] = 'y';
    cout << string << endl;
    cout << second << endl;

    PrintString(string);
    PrintString(second);
   // return 0;//return 0 看不到delete array new两次，害得用cherno视频里面的cin.get()
    cin.get();
}

